<!--
 * @Author: zqx me_zqx@163.com
 * @Date: 2025-01-10 11:38:56
 * @LastEditors: zqx me_zqx@163.com
 * @LastEditTime: 2025-06-26 17:20:51
 * @FilePath: /meeting-minutes-h5/src/views/study/mobile/CustomerGenerat.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="w-full h-screen flex flex-col justify-center items-center">
    <div ref="lottieContainer" style="width: 100px; height: 100px"></div>
    <div class="text-gray-500 text-sm mt-6">
      正在为您生成个性化的能力提升方案，请稍等片刻....
    </div>
  </div>
</template>

<script>
import { mapActions } from "pinia";
import { useStudyStore } from "@/store";
import { showToast } from "vant";
import lottie from "lottie-web";
import animationData from "@/assets/waiting_course_report.json";
import { openPathInNewTab } from "@/utils/urlTool";

export default {
  name: "CustomerGenerat",
  data() {
    return {
      confId: "",
      processValue: 0,
      fileUrl: animationData,
    };
  },
  mounted() {
    const { confId } = this.$route.query;
    this.confId = confId;
    console.log("生成： ", this.confId, this.$route);
    this.generate(confId);
    lottie.loadAnimation({
      container: this.$refs.lottieContainer,
      renderer: "svg",
      loop: true,
      autoplay: true,
      animationData: animationData,
    });
  },
  methods: {
    ...mapActions(useStudyStore, {
      generateUserKngAction: "generateUserKngAction",
    }),
    async generate(confId) {
      if (this.confId) {
        const res = await this.generateUserKngAction(this.confId);
        const { code, message } = res;
        if (code !== 0) {
          showToast(message);
          return;
        }
        const value = parseFloat(res.data);
        this.processValue = value;
        if (value >= 1.0) {
          openPathInNewTab("/study/detail", {
            confId: this.confId,
          });
          this.$router.back();

          return;
        }
        if ((value >= 0) & (value < 1.0)) {
          setTimeout(() => {
            this.generate(confId);
          }, 5000);
        }
      } else {
        showToast("会议号不存在");
      }
    },
  },
};
</script>

<style lang="less" scoped></style>
